package net.lab1024.sa.admin.module.business.erp.poo.service;

import java.util.List;
import net.lab1024.sa.admin.module.business.erp.poo.dao.StoordabackDao;
import net.lab1024.sa.admin.module.business.erp.poo.domain.entity.StoordabackEntity;
import net.lab1024.sa.admin.module.business.erp.poo.domain.form.StoordabackAddForm;
import net.lab1024.sa.admin.module.business.erp.poo.domain.form.StoordabackQueryForm;
import net.lab1024.sa.admin.module.business.erp.poo.domain.form.StoordabackUpdateForm;
import net.lab1024.sa.admin.module.business.erp.poo.domain.vo.StoordabackVO;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 采购入库单行 Service
 *
 * @Author AKITA
 * @Date 2025-08-04 14:53:15
 * @Copyright AKITA
 */

@Service
public class StoordabackService {

    @Resource
    private StoordabackDao stoordabackDao;

    /**
     * 分页查询
     */
    public PageResult<StoordabackVO> queryPage(StoordabackQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<StoordabackVO> list = stoordabackDao.queryPage(page, queryForm);
        return SmartPageUtil.convert2PageResult(page, list);
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(StoordabackAddForm addForm) {
        StoordabackEntity stoordabackEntity = SmartBeanUtil.copy(addForm, StoordabackEntity.class);
        stoordabackDao.insert(stoordabackEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     */
    public ResponseDTO<String> update(StoordabackUpdateForm updateForm) {
        StoordabackEntity stoordabackEntity = SmartBeanUtil.copy(updateForm, StoordabackEntity.class);
        stoordabackDao.updateById(stoordabackEntity);
        return ResponseDTO.ok();
    }

    /**
     * 批量删除
     */
    public ResponseDTO<String> batchDelete(List<Long> idList) {
        if (CollectionUtils.isEmpty(idList)){
            return ResponseDTO.ok();
        }

        stoordabackDao.deleteBatchIds(idList);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Long id) {
        if (null == id){
            return ResponseDTO.ok();
        }

        stoordabackDao.deleteById(id);
        return ResponseDTO.ok();
    }
}
